Ext.define('mvcCouch.model.Supplier', {
    extend: 'Ext.data.Model',
	requires: [
      'mvcCouch.model.Contact',
      'Ext.data.HasManyAssociation',
      'Ext.data.BelongsToAssociation'
    ],
    fields: [
            { name: '_id', type: 'string', mapping: '_id', optional: true, defaultValue: null },
            { name: '_rev', type: 'string', mapping: '_rev', optional: true, defaultValue: null },
            { name: 'companyname', type: 'string', mapping: 'companyname', optional: true, defaultValue: null },
            { name: 'companyaddress', type: 'string', mapping: 'companyaddress', optional: true, defaultValue: null },
            { name: 'postcode', type: 'string', mapping: 'postcode', optional: true, defaultValue: null },
            { name: 'website', type: 'string', mapping: 'website', optional: true, defaultValue: null },
            { name: 'introduction', type: 'string', mapping: 'introduction', optional: true, defaultValue: null },
            { name: 'mainproduct', type: 'string', mapping: 'mainproduct', optional: true, defaultValue: null },
			{ name: 'doctype', type: 'string', mapping: 'doctype', optional: true, defaultValue: 'supplier'}
    ],
	hasMany: { inner: true, model: 'mvcCouch.model.Contact', name: 'contacts' },
    idProperty : '_id',
    proxy: {
        type: 'rest',
        url: 'http://demo.couchdb:5984',
        api: {
            create  : '/editdemo',
            read    : '/_view/getSupplier?reduce=false&include_docs=true',
            update  : '/editdemo',
            destroy : '/editdemo'
        },
        idProperty: '_id',
        appendId: true,
        noCache: true,
        directionParam : '',
        filterParam : '',
        groupParam : '',
        limitParam : 'limit',
        pageParam : '',
        sortParam : '',
        startParam : 'skip',
        //cacheString : '',
        reader: {
            type: 'json',
            root: 'rows',
            record: 'doc',
            idProperty : '_id',
            successProperty: 'ok',
            totalProperty: 'total_rows'
        },
        writer: {
            //nameProperty: 'mapping',
            allowSingle: true,
            encode: false,
            writeAllFields: true,
            root: ''
        }
    }
});